/**
 * @param {string[]} strs
 * @return {string[][]}
 */
var arr = ["eat", "tea", "tan", "ate", "nat", "bat"];

var groupAnagrams = function (strs) {
  let hashMap = new Map();
  for (let i = 0; i < strs.length; i++) {
    let str = [...strs[i]].sort().join("");
    if (hashMap.has(str)) {
      hashMap.set(str, [...hashMap.get(str), strs[i]]);
    } else {
      hashMap.set(str, [strs[i]]);
    }
  }
  return [...hashMap.values()]
};

console.log(groupAnagrams(arr));